<template>
	<view class="">
		<!-- 搜索 -->
		<view class="py-2 bg-white d-flex j-center a-center">
			<view class="px-3 d-flex py-1 rounded-50 span-18 bg-light-secondary">
				<u-icon   name="search" color="" size="28"></u-icon>
				<input class="ml-2" type="text" @confirm="seach_confirm" v-model="keywords"  placeholder="搜索订单" @input="seach_keywords"  />
			</view>
		</view>
		<view class="" v-if="order_list.length<=0">
			<view class="d-flex flex-column j-center a-center h-100 pb-3">
				<image src="../../static/images/home/icon_no_data.png" mode="" class="icon_no_data"></image>
				<view class="">暂无订单</view>
			</view>
		</view>
		<!-- 代发货 -->
		<view class="" v-else>
			<view class="" v-if="status_type!='退货'">
				<view class="m-2 bg-white rounded-20" @click="order_send(item)" v-for="(item,index) in order_list" :key="index">
					<view class="today_title px-3 py-2 rounded-top">
						<view class="d-flex j-sb pt">
							<view class="d-flex a-center">
								<view class="mr-1 rounded-50 d-flex user_img j-center a-center">
									<u-icon name="account-fill" color="#ff6b69" size="30"></u-icon>
								</view>
								<view class="">{{item.mobile}}</view>
							</view>
							<view class="">{{item.label_order_status}}</view>
						</view>
						<view class="d-flex j-sb text-light-muted pt-2">
							<view class="">{{item.create_time}}</view>
							<view class="">{{item.order_sn}}</view>
						</view>
					</view>	
					<view class="p-3">
						<view class="d-flex">
							<image class="today_hot" :src="item.goods_items[0].img.url" mode=""></image>
							<view class="m-2">
								<view class="">{{item.goods_items[0].name}}</view>
								<view class="text-light-muted">属性：500g</view>
							</view>
						</view>
						<view class="py-1">
							<text>共{{item.goods_items[0].goods_number}}件</text><text>合计:{{item.formated_total_fee}}</text>
						</view>
						<view class="">
						<view class="" v-if="item.label_order_status=='待付款'">
							<view class="d-flex j-end">
								<view class="py-1 px-3 border rounded-50" @click="order_payment(item)">付款</view>
								<view class="py-1 px-3 border ml-2 rounded-50" @click="order_mouse(item)">改价</view>
								<view class="py-1 px-3 border ml-2 rounded-50" @click="close(item)">关闭</view>
							</view>
						</view>
						<view class="" v-else-if="item.label_order_status=='已完成'">
							<view class="d-flex j-end">
								<view class="py-1 px-3 border rounded-50" @click="take_flow(item)" >查看物流</view>
								<view class="py-1 px-3 border ml-2 rounded-50" @click="fulfilled_record(item)">备注</view>
							</view>
						</view>
						<view class="" v-else-if="item.label_order_status=='待收货'">
							<view class="d-flex j-end">
								<view class="py-1 px-3 border rounded-50" @click="take_flow(item)" >查看物流</view>
								<view class="py-1 px-3 border ml-2 rounded-50" @click="fulfilled_record(item)">备注</view>
							</view>
						</view>
						<view class="d-flex j-end" v-else-if="item.label_order_status=='待发货'">
							<view class="py-1 px-3 border rounded-50" @click="pyment(item)">发货</view>
							<view class="py-1 px-3 border ml-2 rounded-50" @click="close(item)">关闭</view>
						</view>	
					</view>	
					</view>
				</view>
			</view>
			<view class="" v-else>
				<view class="m-2 bg-white rounded-20" @click="send_detail(item)" v-for="(item,index) in order_list" :key="index">
					<view class="today_title px-3 py-2 rounded-top">
						<view class="d-flex j-sb pt">
							<view class="d-flex a-center">
								<view class="mr-1 rounded-50 d-flex user_img j-center a-center">
									<u-icon name="account-fill" color="#ff6b69" size="30"></u-icon>
								</view>
								<view class="">{{item.mobile}}</view>
							</view>
							<view class="">{{item.label_return_status}}</view>
						</view>
						<view class="d-flex j-sb text-light-muted">
							<view class="">{{item.apply_time}}</view>
							<view class="">{{item.order_sn}}</view>
						</view>
					</view>
					<view class="p-3">
						<view class="d-flex a-center" v-if="item.goods_items.length>1">
							<view  class="mr-1">
								<image class="today_hot rounded-20" :src="item.goods_items.img.url?item.goods_items.img.url:defaltImage" mode=""></image>
							</view>
							<view class="mr-2" v-if="item.goods_items.length>3">
								<u-icon name="more-dot-fill" color="#eaeaea" size="50"></u-icon>
							</view>
						</view>
						<view class="d-flex" v-else>
							<view class="">
								<image class="today_hot rounded-20" :src="item.goods_items.img.url" mode=""></image>
							</view>
							<view class="m-2">
								<view class="ellipsis">{{item.goods_items.goods_name}}</view>
							</view>
						</view>
						<view class="py-1">
							<text>共{{item.goods_items.return_number}}件</text><text>合计:{{item.goods_items.formatted_shop_price}}</text>
						</view>
						<view class="d-flex j-end">
							<view v-if="item.label_return_status=='待审核'" class="py-1 px-3 border rounded-50" @click.stop="agree(item)">同意</view>
							<view v-if="item.label_return_status=='已审核'" class="py-1 px-3 border ml-2 rounded-50" @click.stop="order_back(item)">收到退回商品</view>
							<view v-if="item.label_return_status=='已寄出商品'" class="py-1 px-3 border ml-2 rounded-50" @click.stop="service(item)">完成维修</view>
							<view class="py-1 px-3 border ml-2 rounded-50" @click.stop="remark(item)">备注</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		 data() {
		        return {
		           flag:false,
				   keywords:"", // 关键字
				   status_type:"",  // 订单类型
				   order_list:"", // 搜索列表
				   
				   more:1, // 第几页
				   count:10, // 条数
				   total:0, // 总页数
		        }
		    },
		    methods: {
				// 详情
				order_send(item){
					uni.navigateTo({
						url:"/pagesA/order/order-today-send-detail?order_id="+item.order_id
					})
				},
				// 搜索
				seach_keywords(e){
					this.keywords=e.detail.value
				},
				seach_confirm(){
					if(this.status_type=='退货'){
						this.$H.post("admin/order/return/list",{
							type:"return",
							keywords:this.keywords
						}).then(res=>{
							this.order_list=res.data
						})
					}else{
						this.$H.post("admin/orders/list",{type:this.status_type,keywords:this.keywords}).then(res=>{
							this.order_list=res.data
						})
					}
				},
				// 物流信息
				take_flow(item){
					uni.navigateTo({
						url:"/pagesA/order/order-flow?order_id="+item.order_id
					})
				},
				// 操作记录
				fulfilled_record(item){
					uni.navigateTo({
						url:"/pagesA/order/order-record?order_id="+item.order_id
					})
				},
				// 付款
				order_payment(item){
					uni.navigateTo({
						url:"/pagesA/order/order-confirm?order_id="+item.order_id
					})
				},
				// 改价
				order_mouse(item){
					uni.navigateTo({
						url:"/pagesA/order/order-mouse?order_id="+item.order_id
					})
				},
				// 发货
				pyment(item){
					uni.navigateTo({
						url:"/pagesA/order/order-today-shipments?order_id="+item.order_id
					})
				},
				// 关闭
				close(item){
					uni.navigateTo({
						url:"/pagesA/order/order-close?order_id="+item.order_id
					})
				},
				// 商品详情
				send_detail(item){
					console.log(item.return_id)
					uni.navigateTo({
						url:'/pagesA/order/order-return-detail?return_id='+item.return_id
					})
				},
				// 备注
				remark(item){
					uni.navigateTo({
						url:`/pagesA/order/order-record?order_id=${item.order_id}&return_id=${item.return_id}`
					})
				},
				// 同意
				agree(item){
					this.$H.post("admin/order/return/operate/agree",{
						return_id:item.return_id
					}).then(res=>{
						if(res.data){
							this.$u.toast("申请通过")
							this.$H.post("admin/order/return/list",{
								type:"return",
								pagination:{
									count:this.count,
									page:this.more
								},
								}).then(res=>{
								this.order_list=res.data
							})	
						}else{
							this.$u.toast(res.status.error_desc)
						}
					})
				},
				// 收到退回商品
				order_back(item){
					this.$H.post("admin/order/return/operate/receive",{
						return_id:item.return_id
					}).then(res=>{
						if(res.data){
							this.$u.toast("已确定收到退货商品")
							this.$H.post("admin/order/return/list",{
								type:"return",
								pagination:{
									count:this.count,
									page:this.more
								},
								}).then(res=>{
								this.order_list=res.data
							})	
						}else{
							this.$u.toast(res.status.error_desc)
						}
					})
				},
				// 寄出商品
				rebate(item){
					uni.navigateTo({
						url:`/pagesA/order/order-send-off?order_id=${item.order_id}&return_id=${item.return_id}`
					})
				},
				// 完成维修
				service(item){
					uni.navigateTo({
						url:`/pagesA/order/order-service?order_id=${item.order_id}&return_id=${item.return_id}`
					})
				},
			},
			onShow() {
				if(this.keywords){
					if(this.status_type=='退货'){
						this.$H.post("admin/order/return/list",{
							type:"return",
							keywords:this.keywords
						}).then(res=>{
							this.order_list=res.data
						})
					}else{
						this.$H.post("admin/orders/list",{type:this.status_type}).then(res=>{
							this.order_list=res.data
						})
					}
				}
			},
			onLoad(item) {
				this.status_type=item.order_status_code
			}
	}
</script>
	
<style>
	.user_img{
		width: 40upx;
		height: 40upx;
		background-color: #ffd1d0;
	}
	.today_title{
		background-color: #f6efef;
	}
	.today_hot{
		width: 150upx;
		height: 150upx;
	}	
	.icon_no_data{
		width: 250upx;
		height: 250upx;
	}
	.restore{
		border-radius: 40upx;
		border: 1px solid #555;
	}
</style>
